
#include "stdafx.h"
#include "ProteinVista.h"
#include "ProteinVistaView.h"
#include "PDBRenderer.h"
#include "ProteinVistaRenderer.h"
#include "HeaderDisplayPane.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


BEGIN_MESSAGE_MAP(CHeaderDisplayPane, CWnd)
	ON_WM_CREATE()
	ON_WM_SIZE()
END_MESSAGE_MAP()

int CHeaderDisplayPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (m_wndOutput.GetSafeHwnd() == 0)
	{
		m_wndOutput.Create(WS_HSCROLL|WS_VSCROLL|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_MULTILINE|WS_VISIBLE|ES_READONLY, CRect(0, 0, 0, 0), this, 0 );
		m_wndOutput.ModifyStyleEx(0, WS_EX_STATICEDGE);

		m_wndOutput.SetFont(XTPPaintManager()->GetRegularFont());
		m_wndOutput.SetMargins(10, 5);
	}

	return 0;
}

void CHeaderDisplayPane::OnSize(UINT32 nType, INT32 cx, INT32 cy)
{
	CWnd::OnSize(nType, cx, cy);

	if (m_wndOutput.GetSafeHwnd())
	{
		m_wndOutput.MoveWindow(0, 0, cx, cy);
	}
}


HRESULT CHeaderDisplayPane::OnUpdate()
{
	CSTLArrayPDBRenderer &arrayPDBRenderer = m_pProteinVistaRenderer->m_arrayPDBRenderer;
	SSIZE_T nPDB = arrayPDBRenderer.size();

	CString strHeader;

	if ( nPDB == 0 )
	{
		m_wndOutput.SetWindowText("");
		return S_OK;
	}

	INT32 i;
	strHeader.GetBuffer(1024*100);

	for ( INT32 iHeader = 0 ; iHeader < arrayPDBRenderer.size(); iHeader ++ )
	{
		CPDBInst * pPDBInst = arrayPDBRenderer[iHeader]->GetPDBInst();

		if ( iHeader != 0 )
			strHeader += "\r\n\r\n\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\r\n\r\n";
		strHeader += "<<<< ";
		strHeader += pPDBInst->GetPDB()->m_strPDBID;
		strHeader += " >>>>\r\n\r\n";

		strHeader += "[Header]\r\n";
		for ( i = 0 ; i < pPDBInst->GetPDB()->m_strArrayHeader.GetSize() ; i++ )		{	strHeader += pPDBInst->GetPDB()->m_strArrayHeader[i]; strHeader += "\r\n"; }

		strHeader += "\r\n[Title]\r\n";
		for ( i = 0 ; i < pPDBInst->GetPDB()->m_strArrayTitle.GetSize() ; i++ )		{	strHeader += pPDBInst->GetPDB()->m_strArrayTitle[i]; strHeader += "\r\n"; }

		strHeader += "\r\n[Source:the biological and/or chemical source of each biological molecule in the entry]\r\n";
		for ( i = 0 ; i < pPDBInst->GetPDB()->m_strArraySource.GetSize() ; i++ )		{	strHeader += pPDBInst->GetPDB()->m_strArraySource[i]; strHeader += "\r\n"; }

		strHeader += "\r\n[COMPND:the macromolecular contents of an entry]\r\n";
		for ( i = 0 ; i < pPDBInst->GetPDB()->m_strArrayKeywords.GetSize() ; i++ )		{	strHeader += pPDBInst->GetPDB()->m_strArrayKeywords[i]; strHeader += "\r\n"; }

		strHeader += "\r\n[KEYWDS: a set of terms relevant to the entry]\r\n";
		for ( i = 0 ; i < pPDBInst->GetPDB()->m_strArrayEXPDTA.GetSize() ; i++ )		{	strHeader += pPDBInst->GetPDB()->m_strArrayEXPDTA[i]; strHeader += "\r\n"; }

		strHeader += "\r\n[Author:the names of the people responsible for the contents of the entry]\r\n";
		for ( i = 0 ; i < pPDBInst->GetPDB()->m_strArrayAuthor.GetSize() ; i++ )		{	strHeader += pPDBInst->GetPDB()->m_strArrayAuthor[i]; strHeader += "\r\n"; }

		strHeader += "\r\n[RevisionDate:a history of the modifications made to an entry since its release]\r\n";
		for ( i = 0 ; i < pPDBInst->GetPDB()->m_strArrayRevisionDate.GetSize() ; i++ ){	strHeader += pPDBInst->GetPDB()->m_strArrayRevisionDate[i]; strHeader += "\r\n"; }

		strHeader += "\r\n[JournalCitation:the primary literature citation ]\r\n";
		for ( i = 0 ; i < pPDBInst->GetPDB()->m_strArrayJournalCitation.GetSize() ; i++ ){	strHeader += pPDBInst->GetPDB()->m_strArrayJournalCitation[i]; strHeader += "\r\n"; }

		strHeader += "\r\n[Remark:the macromolecular contents of an entry]\r\n";
		for ( i = 0 ; i < pPDBInst->GetPDB()->m_strArrayRemark.GetSize() ; i++ )		{	strHeader += pPDBInst->GetPDB()->m_strArrayRemark[i]; strHeader += "\r\n"; }

	}

	m_wndOutput.SetWindowText(strHeader);
	return S_OK;
}

void	CHeaderDisplayPane::Delete()
{
	m_wndOutput.Clear();
}

